package com.team11.server.controller.admin;

import com.team11.server.pojo.SelKcInformation;
import com.team11.server.service.admin.Admin_UpdateKc_Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@CrossOrigin
@RestController
@Api(tags = "管理员接口")
public class Admin_UpdateKc_Controller {
    @Autowired
    private Admin_UpdateKc_Service admin_updateKc_service;
    @ApiOperation("点击进入课程编辑界面获取课程信息(需要skid)")
    @PostMapping("/SelKc")
    public List<SelKcInformation> updateKc(Integer sKid){
        return admin_updateKc_service.updateKc(sKid);
    }

    @ApiOperation("编辑课程信息")
    @PostMapping("/UpdateKc")
    public String updateKc(Integer skId,String kcDate,String kcName,String zRTeacher
            ,String kcInTime,String kcOutTime,String kcClassroom,String kcRemarks,@RequestParam(value = "SxTeachers" ,required=false)List<String> SxTeachers){
     if (SxTeachers!=null){
         admin_updateKc_service.DeleteSxT(skId);
     }


        HashMap<String,Object> map=new HashMap<>();
        map.put("kcDate",kcDate);
        map.put("kcInTime",kcInTime);
        map.put("kcOutTime",kcOutTime);
        map.put("kcClassroom",kcClassroom);
        map.put("kcName",kcName);
        map.put("zRtName",zRTeacher);
        map.put("skId",skId);
        map.put("kcRemarks",kcRemarks);
        admin_updateKc_service.UpdateSk(map);
     admin_updateKc_service.UpdateKcZrT(map);
     for (String sxTeacher:SxTeachers){
         map.put("sxTeacher",sxTeacher);
         admin_updateKc_service.InsertSxT(map);
     }
     return "执行成功";
    }
}
